import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/pre_sale/pre_sale_page.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';
import 'package:provider/provider.dart';

import 'pre_sale_provider.dart';

//支付按钮
class PreSaleActivityButton extends StatelessWidget {
  final Function() onTap;
  const PreSaleActivityButton({super.key, required this.onTap});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 6),
        child: NetworkImageLoader(
          fit: BoxFit.fill,
          imageUrl: PreSaleProvider().generatePayButtonTitle(),
        ),
      ),
    );
  }
}

//首页 - 预付弹窗
class PreSaleBookingAlert extends StatelessWidget {
  const PreSaleBookingAlert({super.key});

  @override
  Widget build(BuildContext context) {
    return Transform.translate(
      offset: Offset(0, -30),
      child: GestureDetector(
        onTap: () {
          Get.back();
          Get.toNamed(PreSalePage.routeName);
        },
        child: Center(
          child: Material(
            color: Colors.transparent,
            child: Consumer<PreSaleProvider>(
              builder: (context, provider, child) {
                return NetworkImageLoader(
                  imageUrl: provider.advancePage?.popBgWait ?? '',
                  placeHolderWidget: Container(height: 370, color: Color(0xffE6E6E6)),
                );
              },
            ),
          ).paddingSymmetric(horizontal: 30),
        ),
      ),
    );
  }
}

//首页 - 支付尾款弹窗
class PreSaleBalancePayAlert extends StatefulWidget {
  const PreSaleBalancePayAlert({super.key});

  @override
  State<PreSaleBalancePayAlert> createState() => _PreSaleBalancePayAlertState();
}

class _PreSaleBalancePayAlertState extends State<PreSaleBalancePayAlert> {
  @override
  Widget build(BuildContext context) {
    return Transform.translate(
      offset: Offset(0, -30),
      child: GestureDetector(
        onTap: () {
          Get.back();
          Get.toNamed(PreSalePage.routeName);
        },
        child: Center(
          child: Material(
            color: Colors.transparent,
            child: Container(
              height: 370,
              child: Stack(
                alignment: Alignment.center,
                children: [
                  Consumer<PreSaleProvider>(
                    builder: (context, provider, child) {
                      return NetworkImageLoader(
                        imageUrl: provider.advancePage?.popBgProc ?? '',
                        placeHolderWidget: Container(
                          height: 370,
                          color: Color(0xffE6E6E6),
                        ),
                      );
                    },
                  ),
                  Positioned(
                    top: 235,
                    child: ValueListenableBuilder(
                      valueListenable: PreSaleProvider().deadline,
                      builder: (BuildContext context, String time, Widget? child) {
                        return Text(
                          '剩余时间：$time',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.w700,
                          ),
                        );
                      },
                    ),
                  )
                ],
              ),
            ),
          ).paddingSymmetric(horizontal: 30),
        ),
      ),
    );
  }
}
